// const BASE_URL = 'http://api-breakingnews-web.itheima.net'
// 个人中心 基本资料
function myGetUserInfo() {
  myUserInfo(res => {
    let { id, username, nickname, email } = res.data.data
    $('input[name=username]').val(username)
    $('input[name=nickname]').val(nickname)
    $('input[name=email]').val(email)
    $('input[name=id]').val(id)
  })
}
myGetUserInfo()

// 校验
let form = window.layui.form
form.verify({
  nickname: function (value) {
    if (!/^[\u4E00-\u9FA5]+$/.test(value)) {
      return '昵称必须为中文'
    }
  }
})

// 提交修改
$('.layui-form').on('submit', function (e) {
  e.preventDefault()

  let nickname = $('input[name=nickname]').val()
  let email = $('input[name=email]').val()
  let id = $('input[name=id]').val()
  let data = `nickname=${nickname}&email=${email}&id=${id}`

  editUserInfo(data, res => {
    let { status, message } = res.data
    if (status === 0) {
      successMsg(message, () => {
        window.parent.getUserInfo()
      })
    }
  })
})

// 点击重置
$('.my-reset').on('click', function () {
  myGetUserInfo()
})
